const page = dir => () => import('@/pages/' + dir);

let loadComponent = function(routeInfo) {
    let list = [];
    routeInfo.forEach(item => {
        let r = {
            path: item.path,
            name: item.name,
            component: item.dir ? page(item.dir) : null,
            redirect: item.redirect ? item.redirect : null,
        };
        if (item.level === 0) {
            r.children = loadComponent(item.children);
        } else if (item.children) {
            let child = loadComponent(item.children);
            list = list.concat(child);
        }
        if (item.path) {
            list.push(r);
        }
    });
    return list;
};

export default loadComponent;